/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * POIDisplay.java
 *
 * Created on Jul 24, 2008, 2:08:31 PM
 */

package spring;

import javax.swing.*;
import javax.swing.event.*;

/**
 *
 * @author spring
 */
public class POIDisplay extends javax.swing.JPanel {

    /** Creates new form POIDisplay */
    public POIDisplay() {
        initComponents();
        Terms.setModel(dfl);
       
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Name = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        Color = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        Terms = new javax.swing.JList();
        XLoc = new javax.swing.JTextField();
        YLoc = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        AddField = new javax.swing.JButton();
        SaveMod = new javax.swing.JButton();
        RemoveField = new javax.swing.JButton();
        TermName = new javax.swing.JTextField();
        TermWeight = new javax.swing.JTextField();

        Name.setColumns(10);
        Name.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NameActionPerformed(evt);
            }
        });
        Name.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                NameFocusLost(evt);
            }
        });

        jLabel1.setText("Name");

        Color.setText("Change Color");
        Color.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ColorActionPerformed(evt);
            }
        });

        Terms.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        Terms.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        Terms.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TermsMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(Terms);

        XLoc.setColumns(5);
        XLoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                XLocActionPerformed(evt);
            }
        });
        XLoc.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                XLocFocusLost(evt);
            }
        });

        YLoc.setColumns(5);
        YLoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                YLocActionPerformed(evt);
            }
        });
        YLoc.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                YLocFocusLost(evt);
            }
        });

        jLabel2.setText("Y");

        jLabel3.setText("X");

        jLabel4.setText("Initial Location");

        AddField.setText("Add Field");
        AddField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddFieldActionPerformed(evt);
            }
        });

        SaveMod.setText("Save Modify");
        SaveMod.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveModActionPerformed(evt);
            }
        });

        RemoveField.setText("Remove Field");
        RemoveField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RemoveFieldActionPerformed(evt);
            }
        });

        TermName.setColumns(12);

        TermWeight.setColumns(5);
        TermWeight.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TermWeightActionPerformed(evt);
            }
        });
        TermWeight.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                TermWeightKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(SaveMod, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(AddField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(RemoveField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(TermName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(TermWeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(83, 83, 83))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(XLoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(YLoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(139, 139, 139)))
                .addGap(55, 55, 55))
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(Name, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 107, Short.MAX_VALUE)
                .addComponent(Color, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(96, 96, 96))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(Name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Color))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(TermName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(TermWeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(37, 37, 37)
                        .addComponent(SaveMod)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(AddField)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(RemoveField)
                        .addGap(42, 42, 42)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2)
                    .addComponent(YLoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(XLoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void TermsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TermsMouseClicked
//if (evt.getModifiers()==java.awt.event.InputEvent.BUTTON3_MASK)
        int index= Terms.locationToIndex(new java.awt.Point(evt.getX(),evt.getY()));
        Terms.setSelectedIndex(index);
        String tmp = (String)Terms.getSelectedValue();
        String[] parts = tmp.split(",");
        TermName.setText(parts[0]);
        TermWeight.setText(parts[1]);
    }//GEN-LAST:event_TermsMouseClicked

    private void SaveModActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveModActionPerformed
        // TODO add your handling code here:
        int index = Terms.getSelectedIndex();
        DefaultListModel dlm = (DefaultListModel)Terms.getModel();
        dlm.setElementAt(TermName.getText()+","+TermWeight.getText(),index);
    }//GEN-LAST:event_SaveModActionPerformed

    private void RemoveFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RemoveFieldActionPerformed
        // TODO add your handling code here:
        int index = Terms.getSelectedIndex();
        DefaultListModel dlm = (DefaultListModel)Terms.getModel();
        dlm.removeElementAt(index);
        TermName.setText("");
        TermWeight.setText("");
        if (index<Terms.getLastVisibleIndex())
            Terms.setSelectedIndex(index);
        else
            Terms.setSelectedIndex(Terms.getLastVisibleIndex());
    }//GEN-LAST:event_RemoveFieldActionPerformed

    private void AddFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddFieldActionPerformed
        // TODO add your handling code here:
        DefaultListModel dlm = (DefaultListModel)Terms.getModel();
        dlm.addElement(TermName.getText()+","+TermWeight.getText());
        Terms.setSelectedIndex(Terms.getLastVisibleIndex());
    }//GEN-LAST:event_AddFieldActionPerformed

    private void ColorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ColorActionPerformed
        // TODO add your handling code here:
        java.awt.Color existingbg = this.getBackground();
        java.awt.Color newbg = JColorChooser.showDialog(null, "JColorChooser Sample", existingbg);
        if (newbg != null) {
          this.setBackground(newbg);
        }
    }//GEN-LAST:event_ColorActionPerformed

    private void NameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NameActionPerformed
        // TODO add your handling code here:
        this.name = Name.getText();
    }//GEN-LAST:event_NameActionPerformed

    private void XLocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_XLocActionPerformed
        // TODO add your handling code here:
        this.X = new Double(XLoc.getText()).doubleValue();
    }//GEN-LAST:event_XLocActionPerformed

    private void YLocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_YLocActionPerformed
        // TODO add your handling code here:
        this.Y = new Double(YLoc.getText()).doubleValue();
    }//GEN-LAST:event_YLocActionPerformed

    private void NameFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_NameFocusLost
        // TODO add your handling code here:
        this.name = Name.getText();
    }//GEN-LAST:event_NameFocusLost

    private void XLocFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_XLocFocusLost
        // TODO add your handling code here:
        this.X = new Double(XLoc.getText()).doubleValue();
    }//GEN-LAST:event_XLocFocusLost

    private void YLocFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_YLocFocusLost
        // TODO add your handling code here:
        this.Y = new Double(YLoc.getText()).doubleValue();
    }//GEN-LAST:event_YLocFocusLost

    private void TermWeightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TermWeightActionPerformed
        // TODO add your handling code here:
        int index = Terms.getSelectedIndex();
        DefaultListModel dlm = (DefaultListModel)Terms.getModel();
        dlm.setElementAt(TermName.getText()+","+TermWeight.getText(),index);
    }//GEN-LAST:event_TermWeightActionPerformed

    private void TermWeightKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TermWeightKeyTyped
        // TODO add your handling code here:
        int index = Terms.getSelectedIndex();
        DefaultListModel dlm = (DefaultListModel)Terms.getModel();
        dlm.setElementAt(TermName.getText()+","+TermWeight.getText(),index);
    }//GEN-LAST:event_TermWeightKeyTyped

   public void setColor(int r, int g, int b){
        this.bgcolor = new java.awt.Color(r,g,b);
        this.setBackground(bgcolor);
    }
   public java.awt.Color getColor(){
        return this.getBackground();
    }
   public void setXloc(double x){
        this.X = x;
        XLoc.setText(new Double(X).toString());
    }
   public double getXloc(){
        return X;
    }
   public void setYloc(double y){
        this.Y = y;
        YLoc.setText(new Double(Y).toString());
    }
   public double getYloc(){
        return Y;
    }
   public void setName(String name){
        this.name = name;
        Name.setText(name);
    }
   public String getName(){
        return name;
    }
   public void setTerm(String term){
        this.dfl.addElement(term);
    }
   public String getTerm(){
       if (this.dfl.isEmpty()){
        return null;
       }
       else{
        String tmp = (String) this.dfl.firstElement();
        this.dfl.remove(0);
        return tmp;

       }
    }
   private javax.swing.DefaultListModel dfl=new javax.swing.DefaultListModel() ;
   private String name=null;
   private java.awt.Color bgcolor=null;
   private double  X=0.0, Y=0.0;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AddField;
    private javax.swing.JButton Color;
    private javax.swing.JTextField Name;
    private javax.swing.JButton RemoveField;
    private javax.swing.JButton SaveMod;
    private javax.swing.JTextField TermName;
    private javax.swing.JTextField TermWeight;
    private javax.swing.JList Terms;
    private javax.swing.JTextField XLoc;
    private javax.swing.JTextField YLoc;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
